<template>

	<view class="promotersSettingCard">
		<view class="font-weight_bold font36">
			基本设置
		</view>
		<view class="margin-top_20rpx">
			<view class="font-weight_bold">冻结状态</view>
		</view>
		<view class="margin-top_20rpx">
			<radio-group v-model="form.sex" name="apply" @change="handleApplyType">

				<label class="m-right10">
					<radio style="transform:scale(0.6)" :checked="form.state ==1" class="min-radio" value="1"
						color="#1E6CEB" />
					<text>正常</text>
				</label>
				<label>
					<radio style="transform:scale(0.6)" :checked="form.state ==2" class="min-radio" value="2"
						color="#1E6CEB" />
					<text>冻结</text>
				</label>
			</radio-group>
		</view>
		<view class="margin-top_20rpx">
			<view class="font-weight_bold">推广员名称</view>

			<view class="" style="color: #999999;" v-if="isEdit">
				<text>当前账户名称：<text style="color: red;">{{form.name}}</text></text>
			</view>
			<view class="">
				<input class="uni-inputsa" type="text" v-model="form.name " placeholder="请输入推广员名称" />
			</view>
		</view>
		<view class="margin-top_20rpx">
			<view class="font-weight_bold">推广员账户</view>

			<view class="" style="color: #999999;" v-if="isEdit">
				<text>当前账户<text style="color: red;">{{form.account}}</text></text>
			</view>
			<view class="">
				<input class="uni-inputsa" type="text" v-model="form.account " placeholder="请输入推广员账号/手机号" />
			</view>
		</view>
		<view class="margin-top_20rpx">
			<view class="font-weight_bold">推广员密码</view>

			<view class="" style="color: #999999;" v-if="isEdit">
				<text>当前账户的密码<text style="color: red;">{{form.password}}</text></text>
			</view>
			<view class="">
				<input class="uni-inputsa"  :password="showPassword" v-model="form.password " placeholder="请输入推广员密码" />
			</view>
		</view>

		<view class="font-weight_bold font36 margin-top_40rpx">
			比例设置
		</view>
		<view class="margin-top_20rpx">
			<view class="font-weight_bold margin-top_40rpx" style="color:#333333;">搭子比例</view>


			<view class="allInput">
				<input class="uni-inputs" type="text" v-model="form.daziPercent " placeholder="请输入搭子比例占比" />
				<view class="proportion flex">
                 %
				</view>
				
			</view>
			<text style="color: #999999;">推广员除去平台合伙人可获得的抽成比例</text>
		</view>
		<view class="margin-top_20rpx">
			<view class="font-weight_bold margin-top_40rpx" style="color:#333333;">社群比例</view>


			<view class="allInput">
				<input class="uni-inputs" type="text" v-model="form.communityPercent " placeholder="请输入社群比例占比" />
				<view class="proportion flex">
			     %
				</view>
			</view>
			<text style="color: #999999;">推广员除去平台合伙人可获得的抽成比例</text>
		</view>
		<view class="margin-top_20rpx">
			<view class="font-weight_bold margin-top_40rpx" style="color:#333333;">服务比例</view>
		
		
			<view class="allInput">
				<input class="uni-inputs" type="text" v-model="form.servicePercent " placeholder="请输入服务比例占比" />
				<view class="proportion flex">
			     %
				</view>
				
			</view>
			<text style="color: #999999;">推广员除去平台合伙人可获得的抽成比例</text>
		</view>
		
		<view class="confirmRecharge flex" @click="releaseFn()">
			{{isEdit?'编辑':'新增'}}
		</view>
		

	</view>

</template>

<script>
	export default {
		components: {

		},
		data() {

			return {
				showPassword:true,
				userInfo: uni.getStorageSync("userInfo"),
				associateGetInfo: uni.getStorageSync("associateGetInfo"),
				form: {
					pid:uni.getStorageSync("associateGetInfo").id,
					// 1正常 2冻结
					// frozen: '1',
					// 名字
					name: '',
					// 账号
					account:'',
					password:'',
					// 搭子比例
					daziPercent: '',
					// 服务比例
					servicePercent: '',
					// 社群比例
					communityPercent:'',
				
					state:1
				},
				isEdit:false,

			}
		},
		onShow() {
			this.$at.releaseKey('submit');
			
			
		},
		onLoad(options) {
			if (options.id) {
			
			
			
				const decodedData = {};
				for (const key in options) {
					// 解码当前字段的值
					const decodedValue = decodeURIComponent(options[key]);
			
					// 将解码后的值存储到新的对象中
					decodedData[key] = decodedValue;
				}
			
			
				this.form.id = decodedData.id
				this.$sun.assignObject(this.form, {
					...decodedData
				})
				this.form.daziPercent=decodedData.dazi_percent
				this.form.servicePercent=decodedData.service_percent
				this.form.communityPercent=decodedData.community_percent
			
			
				console.log(this.form)
				this.isEdit = true
			
			}
		},
		methods:{
			handleApplyType(e) {
				let val = e.detail.value;
				this.form.state = val;
				console.log(e.detail.value);
				
			
			},
			
			releaseFn() {
				if (this.userInfo.disable == 0) {
					this.$sun.toast('该用户已被拉黑', 'none')
				}else{
					console.log(this.form)
				
				
						this.$at.uniDoFunc({
							key: 'submit',
							success: async () => {
								this.$at.lockKey('submit');
								// 登录 需要进行判断当前账号密码 和账号归属店铺及角色是否又选择
								if ((!this.form.daziPercent)||this.form.daziPercent>100) {
									this.$sun.toast("请填写搭子比例或者填入的比例超出100", 'none')
									this.$at.releaseKey('submit');
								} else if (!this.form.name) {
									this.$sun.toast("请填写推广员名称", 'none')
									this.$at.releaseKey('submit');
								} else if (!this.form.account) {
									this.$sun.toast("请填写推广员账号", 'none')
									this.$at.releaseKey('submit');
								} else if (!this.form.password ) {
									this.$sun.toast("请选择推广员密码", 'none')
									this.$at.releaseKey('submit');
								} else if ((!this.form.servicePercent)||this.form.servicePercent>100) {
									this.$sun.toast("请填写服务比例或者填入的比例超出100", 'none')
									this.$at.releaseKey('submit');
								} else if ((!this.form.communityPercent)||this.form.communityPercent>100) {
									this.$sun.toast("请填写社群比例或者填入的比例超出100", 'none')
									this.$at.releaseKey('submit');
								} 
								// else if (!this.form.work_time) {
								// 	this.$sun.toast("请填写服务时间", 'none')
								// 	this.$at.releaseKey('submit');
								// } 
								 else {
									console.log(this.form)
					
									const saveOrUpdate = this.isEdit ? this.$api.promoterEdit  : this.$api
										.promoterAdd;
									const result = await this.$http.post({
										url: saveOrUpdate,
										data: {
											...this.form
					
										},
										headers: {
											'Authorization': this.userInfo.token
										}
					
									})
									if (result.code == 0) {
					
										this.$sun.toast(result.message, 'none')
										uni.removeStorageSync('tabClassIfy')
										setTimeout(() => {
											this.$sun.navBack()
										}, 500)
					
					
					
									} else {
										this.$sun.toast(result.message, 'none')
									}
					
									this.$at.releaseKey('submit');
								}
							}
						});
					
				}
				
			
			
			},
		}
	}
</script>

<style lang="less">
	page {
		background-color: #fff;
	}

	.promotersSettingCard {
		.confirmRecharge {
			
			margin-top: 40rpx;
			width: 708rpx;
			height: 104rpx;
			border-radius: 102rpx;
			color: #fff;
			background: rgb(120, 93, 246);
		}
		padding: 40rpx 20rpx;
          
		input {
			text-align: left;
		}

		.uni-input {

			height: 100rpx;
		}

		.allInput {
			position: relative;

			.uni-inputs {
				width: 100%;
				height: 90rpx;
				border-radius: 20rpx;
				background: rgb(245, 245, 245);
				margin: 20rpx 0;
				padding: 0rpx 20rpx;
				box-sizing: border-box;
			}

			.proportion {
				position: absolute;
				bottom:2rpx;
				right:2rpx;
				width: 76rpx;
				height: 86rpx;
				border-radius: 20rpx;
                z-index: 999;
				background: rgb(255, 255, 255);
			}
		}

		.uni-inputsa {
			width: 100%;
			height: 90rpx;
			border-radius: 20rpx;
			background: rgb(245, 245, 245);
			margin: 20rpx 0;
			padding: 0rpx 20rpx;
			box-sizing: border-box;
		}

		.uni-inputs {
			text-align: left !important;
		}
	}
</style>